﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class TournamentDelete : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            okmsg.Style["display"] = "none";
            badmsg.Style["display"] = "none";

            sel_tour.DataSource = Tournament.getAvailableTournaments();
            sel_tour.DataTextField = "Tournament_Name";
            sel_tour.DataValueField = "Pk_Tournament";
            sel_tour.DataBind();
            if (sel_tour.Items.Count > 0)
            {
                sel_tour.SelectedIndex = 0;

                Tournament oTournament = new Tournament(int.Parse(sel_tour.SelectedValue));
                txt_name.Value = oTournament.Tournament_Name;
                txt_players.Value = oTournament.QualifyPlayersToPlayOffs.ToString();
                txt_playoffs.Value = oTournament.PlayOffsRounds.ToString();
                txt_rounds.Value = oTournament.QualifyRounds.ToString();
            }
            else {
                txt_name.Value = string.Empty;
                txt_players.Value = string.Empty;
                txt_playoffs.Value = string.Empty;
                txt_rounds.Value = string.Empty;
          
            }
        }
        AjaxPro.Utility.RegisterTypeForAjax(typeof(TournamentDelete));
    }

    protected void sel_tour_SelectedIndexChanged(object sender, EventArgs e)
    {
        Tournament oTournament = new Tournament(int.Parse(sel_tour.SelectedValue));
            
        txt_name.Value = oTournament.Tournament_Name;
        txt_players.Value = oTournament.QualifyPlayersToPlayOffs.ToString();
        txt_playoffs.Value = oTournament.PlayOffsRounds.ToString();
        txt_rounds.Value = oTournament.QualifyRounds.ToString();   

    }
   
    protected void DeleteBtn_ServerClick1(object sender, EventArgs e)
    {
        try
        {
            Boolean res = Tournament.DeleteTournament(int.Parse(sel_tour.SelectedValue));
            if (res == true)
            {
                okmsg.Style["display"] = "block";
                sel_tour.DataSource = Tournament.getAvailableTournaments();
                sel_tour.DataTextField = "Tournament_Name";
                sel_tour.DataValueField = "Pk_Tournament";
                sel_tour.DataBind();

                if (sel_tour.Items.Count > 0)
                {
                    sel_tour.SelectedIndex = 0;
                    Tournament oTournament = new Tournament(int.Parse(sel_tour.SelectedValue));
                    txt_name.Value = oTournament.Tournament_Name;
                    txt_players.Value = oTournament.QualifyPlayersToPlayOffs.ToString();
                    txt_playoffs.Value = oTournament.PlayOffsRounds.ToString();
                    txt_rounds.Value = oTournament.QualifyRounds.ToString();
                }
                else {
                    txt_name.Value = string.Empty;
                    txt_players.Value = string.Empty;
                    txt_playoffs.Value = string.Empty;
                    txt_rounds.Value = string.Empty;
                }
            }
            else
            {
                badmsg.Style["display"] = "block";
            }
        }
        catch (Exception)
        {
            badmsg.Style["display"] = "block";
        }

        //Borrado de torneo
    }
}
